Skip to content

Conversation

Az-CMQ
Copy link

@Az-CMQ Az-CMQ commented Sep 14, 2025

Background

The loudness() function in torchaudio.functional implements the ITU-R BS.1770-4 loudness measurement. It applies both absolute and relative gating to compute energy-averaged LKFS values.

Issue

When all audio blocks are below the absolute gating threshold (gamma_abs = -70), the computation of energy_filtered involves division by the count of gated blocks, which is zero in this scenario. This results in a NaN output. This edge case commonly occurs for very quiet or silent audio signals.

Changes

  • Introduced torch.where to safely handle cases where the count of gated blocks is zero.
  • When no blocks pass the gating threshold, energy_filtered is set to zero.
  • Separate variables (abs_gated_blocks and rel_gated_blocks) are used to clearly distinguish absolute and relative gating steps.
  • Maintained compatibility with ITU-R BS.1770-4 standard for normal audio signals.

Impact

  • Prevents NaN values for extremely low-level signals.
  • No change in behavior for signals with blocks above the threshold.
  • Safe for both CPU and CUDA devices.

@Az-CMQ Az-CMQ requested a review from a team as a code owner September 14, 2025 04:40
Copy link

pytorch-bot bot commented Sep 14, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4110

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 35c7f31 with merge base 87ff22e (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed label Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant